import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        String s, come, go;
        String earlyS = "0", lateS = "0";
        String early = "9", late = "0";

        int n = in.nextInt();

        while(n-- != 0) {
            s = in.next();
            come = in.next();
            go = in.next();
            if(come.compareTo(early) < 0) {
                earlyS = s;
                early = come;
            }
            if(go.compareTo(late) > 0) {
                lateS = s;
                late = go;
            }
        }
        System.out.println(earlyS + " " + lateS);
    }
}
